import pymysql

connection = None
cursor = None
try:
    connection = pymysql.connect(host="localhost", port=3306, user="root", passwd="<PASSWORD>",database="test", charset="utf8")
    cursor = connection.cursor()
    cursor.execute("select * from user;")
    cursor.fetchone()
    # 回零
    cursor.rownumber = 0
    cursor.fetchmany(2)
    cursor.rownumber = 0
    cursor.fetchall()
    # 获取第3和第4条数据
    cursor.rownumber = 0
    cursor.fetchmany(2)
except Exception as e:
    print(e)
    raise
finally:
    cursor.close()
    connection.close()



